package progress.exa29_1.noUi;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

public class Client {

    public static void main(String[] args) {
        DataOutputStream toServer=null;//声明输出流
        DataInputStream fromServer=null;//声明输入流
        try{
            //创建套接字
            Socket socket = new Socket("localhost",8000);

            //创建客户端接受和发送数据的流
            fromServer = new DataInputStream(socket.getInputStream());
            toServer = new DataOutputStream(socket.getOutputStream());

            while (true){
                System.out.println("请输入半径：");
                Scanner sc = new Scanner(System.in);
                double radius = sc.nextDouble();
                //将radius写入输出流发送出去
                toServer.writeDouble(radius);
                toServer.flush();//清空输出流
                //从输入流中获取的值赋给area(此方法会阻塞)
                double area = fromServer.readDouble();
                System.out.println("半径："+radius+'\n');
                System.out.println("面积是： "+area+'\n');
            }

        }catch(IOException ex) {
            ex.printStackTrace();
        }

    }

}
